package com.woniuxy.yygy.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.util.pattern.PathPatternParser;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO: 处理跨域问题的配置类
 * <P> Date: 2022/3/3:8:46
 * <P> Description:
 */
@Configuration
public class CorsConfig {

    @Bean
    public CorsWebFilter corsFilter(){
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedMethod("*");
        config.addAllowedOrigin("*");
        config.addAllowedHeader("*");

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
        //任意路径都会被我匹配
        source.registerCorsConfiguration("/**", config);

        return new CorsWebFilter(source);
    }
}
